﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using ImageConverter;
using System.Drawing;

namespace DAL
{
    public class Context : DbContext
    {
        public DbSet<User> Users { get; set; }
        public DbSet<Product> Products { get; set; }
        public DbSet<ProductCategory> ProductCatigories { get; set; }

        public Context():base("MyShopDB")
        {
            Database.SetInitializer<Context>(new ContextInitializer());
        }
    }


    public class ContextInitializer : DropCreateDatabaseAlways<Context>
    {
        ImageConv ic = new ImageConv();
        protected override void Seed(Context context)
        {
            context.Users.Add(new User() { eMail = "romeeo82@gmail.com", password = "123", firstName = "Roman", lastName = "Sokolenko" });
            context.Users.Add(new User() { eMail = "vbelich@gmail.com", password = "123", firstName = "Valeriy", lastName = "Belich" });
            context.Users.Add(new User() { eMail = "mevsukov@gmail.com", password = "123", firstName = "Maxim", lastName = "Evsukov" });
            ProductCategory pcWeapon = new ProductCategory() { categoryName = "Weapon" };
            context.ProductCatigories.Add(pcWeapon);
            context.Products.Add(new Product() { productName = "AK-47", productPrise = 50.0m, productDescription = "prodused in 1947", category = pcWeapon, image = ic.imageToByteArray(Image.FromFile(@"D:\AK-47.jpg")) });
            context.Products.Add(new Product() { productName = "PM", productPrise = 10.0m, productDescription = "prodused in USSR", category = pcWeapon, image = ic.imageToByteArray(Image.FromFile(@"D:\Makarov-Pistol.jpg")) });
            context.Products.Add(new Product() { productName = "Desert Eagle", productPrise = 250.0m, productDescription = "prodused in USA", category = pcWeapon, image = ic.imageToByteArray(Image.FromFile(@"D:\DesertEagle.jpg")) });
            ProductCategory pcHores = new ProductCategory() { categoryName = "Hores" };
            context.Products.Add(new Product() { productName = "Josephine", productPrise = 50.0m, productDescription = "blond 90/60/90 50kg", category = pcHores, image = ic.imageToByteArray(Image.FromFile(@"D:\Josephine.jpg")) });
            context.Products.Add(new Product() { productName = "Julia", productPrise = 12.50m, productDescription = "bald 120/120/120 130kg", category = pcHores, image = ic.imageToByteArray(Image.FromFile(@"D:\лысая.jpg")) });
            context.Products.Add(new Product() { productName = "Rozalin", productPrise = 100.0m, productDescription = "Hot Brunet 100/60/92", category = pcHores, image = ic.imageToByteArray(Image.FromFile(@"D:\брюнетка.jpg")) });
            ProductCategory pcAlkohol = new ProductCategory() { categoryName = "Alkohol" };
            context.Products.Add(new Product() { productName = "Rum", productPrise = 5.20m, productDescription = "Dominicanian rum spiced", category = pcAlkohol, image = ic.imageToByteArray(Image.FromFile(@"D:\ром.jpg")) });
            context.Products.Add(new Product() { productName = "Gin", productPrise = 12.45m, productDescription = "London dry gin", category = pcAlkohol, image = ic.imageToByteArray(Image.FromFile(@"D:\gin.jpg")) });
            context.Products.Add(new Product() { productName = "Vhiskey", productPrise = 14.99m, productDescription = "Scotch whiskey", category = pcAlkohol, image = ic.imageToByteArray(Image.FromFile(@"D:\whiskey.jpg")) });
        }
    }
}
